<template>
  <div class="skillart" @click="toart(item)">
    <div class="left">
      <h3 v-html="item.title"></h3>
      <div class="info">
        <span class="time">{{ item.created_at | formatTime }}</span>
        <span><van-icon name="eye-o" /> {{ item.read }}</span>
        <span
          ><van-icon
            name="good-job-o"
            @click.stop="zan(item.id)"
            :class="iszan ? 'red' : ''"
          />
          {{ star }}</span
        >
      </div>
    </div>
    <div class="right">
      <img :src="baseUrl + item.cover" alt="" />
    </div>
  </div>
</template>

<script>
import { starArticle } from '@/api/api.js'
export default {
  props: ['item', 'value'],
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL,
      iszan: false,
      star: ''
    }
  },
  created () {
    this.item.title = this.item.title.replace(
      this.value,
      `<span style="color:red">${this.value}</span>`
    )
    this.star = this.item.star
  },
  methods: {
    // 点赞
    async zan (id) {
      this.iszan = !this.iszan
      const res = await starArticle({ article: id })
      this.star = this.iszan ? res.data.data.num++ : res.data.data.num--
    },

    // 跳转至文章详情
    toart (item) {
      this.$router.push(`/technicDetail/${item.id}`)
    }
  }
}
</script>

<style lang="less" scoped>
.skillart {
  display: flex;
  margin-bottom: 10px;
  .left {
    padding-left: 10px;
    h3 {
      font-weight: normal;
      font-size: 15px;
      padding-right: 26px;
      margin-bottom: 10px;
      margin-left: 7px;
    }
    span {
      font-size: 12px;
      color: #999;
      padding: 0 10px;
    }
    .time {
      margin-right: 24px;
    }
  }
  .right {
    img {
      width: 130px;
      height: 80px;
      margin-right: 15px;
      margin-top: 12px;
    }
  }
  /deep/.van-cell__value {
    color: #666;
  }
  /deep/.van-cell__title {
    font-size: 16px;
  }
  .red {
    color: red;
  }
}
</style>
